//index.js
//获取应用实例
var app = getApp();
Page({
   data:{
     orderListActive:0,
     showOrder:-1,
     window: {},
     page: 1,
     page2:1,
     nodata:0,
     listData: [],
     listData2:[],
     type: 1,
     tabId:0,
     year:0,
     lastpage1: 0,
     lastpage2: 0,
     loading:0,
     loaded1: 0,
     loaded2: 0,
  },

   canvas:function(){
     const ctx = wx.createCanvasContext('myCanvas');
     var window = wx.getSystemInfoSync();
     var windowWidth = window.windowWidth;
     ctx.beginPath()
     ctx.moveTo(0, 0)
     ctx.setFillStyle('#E6848B')
     ctx.bezierCurveTo(0, 80, windowWidth, 90, windowWidth, 0)
     ctx.setStrokeStyle('#E6848B')
     ctx.fill()
     ctx.stroke()
     ctx.draw();
   },

   onLoad: function (options) {
    // console.log(1223434323);
    var that = this;
    // var d = new Date() 
    // that.setData({ type: options.type, year: d.getFullYear() });
    // this.setData({ window: app.globalData.window })
    //app.getUserInfo(function(){
    //   console.log("rere");
    //   var user_info = wx.getStorageSync('user_info');
    //   that.setData({ 'user_info': user_info }); 
    //  // that.getList();
    //  // that.getMyTopic();
    //   //that.canvas();
    // });
    that.getMyTopic();
  
    
    // wx.setNavigationBarTitle({
    //   title: this.data.tabId == 0 ? this.data.year + "小计划" : '推荐'
    // });
  },
  getMyTopic(){
    var user_info = wx.getStorageSync('user_info');
    var that = this;
    var page = that.data.page2;
    if (that.data.loaded2 == 1 ){
      return ;
    }
    that.data.loaded2 = 1;
    //console.log(event_type);
    app.api("sns/topic/list", {
      page: 1,
      user_id: user_info.user_id,
     // type: 'todolist',
     // status:1,
      pid2:0,
      limit: 5,
      cate_id:0,
      order: 'id desc',
    }, function (res) {
      //that.data.loaded2 = 1;
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      if (res.data.list.length > 0) {
        that.setData({ listData2: that.data.listData2.concat(res.data.list) });
      }
      that.data.loading2=0;
      that.data.page2++;
    })
  },
  //api evens/list 活动列表 

   /**
 * 页面上拉触底事件的处理函数
 */
   onReachBottom: function () {
     this.getMyTopic();
   },


     //下拉刷新 
  onPullDownRefresh: function () {
   wx.stopPullDownRefresh();
   // this.getList(1);
    this.getMyTopic();
   },
  bodyclick() {
    console.log('bodyclick');
    if (this.data.orderListActive == 1) {
      this.setData({ orderListActive: 0 });
    }
  },
  tapOrder(e) {
    this.data.orderListActive == 1 ? this.setData({ orderListActive: 0 }) : this.setData({ orderListActive: 1 });
    console.log('tapOrder');
  },
   
   onShow:function(){
     //wx.hideTabBar();
     var showTab = app.getPageData("user/timeline", "showTab");
     var showOrder = app.getPageData("user/timeline", "showOrder");
     var reload = app.getPageData("user/timeline", 'reload2');
     if (showOrder && Number(showOrder) > -1) {
       this.data.showOrder = showOrder;
       app.setPageData("user/timeline", { showOrder: -1 });
       reload = 1;
     }
     if (showTab && Number(showTab) > -1) {
       this.setData({ tabId: 0 });
       app.setPageData("user/timeline", { showTab: -1 });
     }
     console.log(reload);
     if (reload==1){
       //this.getList(1);
       this.getMyTopic();
     }
   },
   changeOrder(e) {
     var key = e.currentTarget.dataset.key;
     var orderBy = e.currentTarget.dataset.order;
     //this.setData({ showOrder: key});
     this.setData({ orderListActive: 0, showOrder: key, orderBy: orderBy });
     if (this.data.tabId == 0) {
       this.getList(1);//加载数据 
     }
   },


})
